﻿#include <iostream>
#include <map>
#include <string>
using namespace std;
map<string, int>change;
string str;
bool isend[100];
struct ztzh
{
    int begin;
    int change;//-1字母 -2数字
    int end;
}changes[100] = {//状态转换表
    {0 ,'b',31},
    {31,'e',32},
    {32,'g',33},
    {33,'i',34},
    {34,'n', 1},
    {31,-1,10},
    {32,-1,10},
    {33,-1,10},
    {34,-1,10},
    {1,-1,10},
    {31,-2,10},
    {32,-2,10},
    {33,-2,10},
    {34,-2,10},
    {1,-2,10},


    {0 ,'i',35},
    {35,'f',2},
    {35,-1,10},
    {2,-1,10},
    {35,-2,10},
    {2,-2,10},


    {0 ,'t',36},
    {36,'h',37},
    {37,'e',38},
    {38,'n',3},
    {36,-1,10},
    {37,-1,10},
    {38,-1,10},
    {3,-1,10},
    {36,-2,10},
    {37,-2,10},
    {38,-2,10},
    {3,-2,10},



    {0 ,'w',39},
    {39,'h',40},
    {40,'i',41},
    {41,'l',42},
    {42,'e',4},
    {39,-1,10},
    {40,-1,10},
    {41,-1,10},
    {42,-1,10},
    {4,-1,10},
    {39,-2,10},
    {40,-2,10},
    {41,-2,10},
    {42,-2,10},
    {4,-2,10},


    {0 ,'d',43},
    {43,'o',5},
    {43,-1,10},
    {5,-1,10},
    {43,-2,10},
    {5,-2,10},


    {0 ,'e',44},
    {44,'n',45},
    {45,'d',6},
    {44,-1,10},
    {45,-1,10},
    {6,-1,10},
    {44,-2,10},
    {45,-2,10},
    {6,-2,10},


    {0 ,-1,10},
    {1 ,-1,10},
    {2 ,-1,10},
    {3 ,-1,10},
    {4 ,-1,10},
    {5 ,-1,10},
    {6 ,-1,10},
    {10,-1,10},
    {10,-2,10},
    {0 ,-2,11},
    {11,-2,11},
    {0 ,'+',13},
    {0 ,'-',14},
    {0 ,'*',15},
    {0 ,'/',16},
    {0 ,':',17},
    {17,'=',18},
    {0 ,'<',20},
    {20,'>',21},
    {20,'=',22},
    {0 ,'>',23},
    {23,'=',24},
    {0 ,'=',25},
    {0 ,';',26},
    {0 ,'(',27},
    {0 ,')',28},


    {0 ,')',28},
    {0 ,'#',0},
    {0 ,0,0}
};
void init()//初始化，将状态转换表写入哈希表
{
    for (int i = 0; i < 100; i++)
    {
        int a = changes[i].begin;
        int b = changes[i].change;
        int c = changes[i].end;
        if (a == b && b == c && c == 0)break;
        string key = to_string(a) + "_" + to_string(b);
        change[key] = c;
        if (c < 30)isend[c] = 1;
    }
}
void input()//输入一个带空格的字符串
{
    str = "";
    string word;
    char ch;
    while (cin >> word) {
        str += word + " ";
        if ((ch = getchar()) == '\n')
            break;
    }
}
string zh(char nc)//分析字符类型 -1字母 -2数字
{
    if (nc >= '0' && nc <= '9')return to_string(-2);
    if ((nc >= 'a' && nc <= 'z') || (nc >= 'A' && nc <= 'Z'))return to_string(-1);
    return "";
}
void cffx()//词法分析
{
    int cd = str.length();
    int now = 0;
    string temp = "";
    for (int i = 0; i < cd; i++)
    {
        char nc = str[i];
        if (nc == '#' && now == 0)//句子结束
        {

            cout << "(" << 0 << "," << "#" << ")" << endl;
            break;
        }
        if (nc == ' ' || nc == '\t' || nc == '\n')//分隔符处理
        {
            if (now == 0)continue;
            if (now == 10)temp = "'" + temp + "'";

            if (!isend[now] && now != 0)
            {
                now = 10;
                temp = "'" + temp + "'";
            }

            cout << "(" << now << "," << temp << ")" << endl;
            now = 0;
            temp = "";
            continue;
        }
        int inc = nc;
        string gkey = to_string(now) + "_" + to_string(inc);//获取key来查表

        if (change.find(gkey) != change.end())//状态转换
        {
            now = change[gkey];
            temp = temp + nc;
            continue;
        }
        string zht = zh(nc);
        if (zht != "")//查表失败后转换为类型处理
        {
            gkey = to_string(now) + "_" + zht;
        }
        
        if (change.find(gkey) != change.end())//类型查表
        {
            now = change[gkey];
            temp = temp + nc;
            continue;
        }
        //查表失败后判断状态是否为终态，终态则说明已经输入一个单词了
        if (now == 10)temp = "'" + temp + "'";
        if (!isend[now] && now != 0)//字符串处理
        {
            now = 10;
            temp = "'" + temp + "'";
            cout << "(" << now << "," << temp << ")" << endl;
            now = 0;
            temp = "";
            i--;
            continue;
        }
        if (isend[now] && now != 0)
        {
            cout << "(" << now << "," << temp << ")" << endl;
            now = 0;
            temp = "";
            i--;
            continue;
        }
        //出错处理
        cout << "未知字符！" << endl;
        now = 0;
        temp = "";
    }
}
int main()
{
    init();
    while (1)
    {
        input();
        cffx();
        cout << "--------------------------------------------------------------" << endl;
    }
}
